classdef BudgetBoundedObjectiveCounter < handle
    %UNTITLED2 Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
    end
    
    methods
        function [o,sp] = compute(obj, ind)
            mask = mask_generator( ind.connections );
            graph_distances = ind.stops.distances + mask;
            ind.shortest_paths = FastFloyd(graph_distances);
            
            % Sprawdzenie spojnosci
            if find( ind.shortest_paths == inf )
                %disp( 'Graf niespojny' )
                sp = false;
            else
                %disp( 'Graf spojny' )
                sp = true;
            end
            
            % Korekcja macierzy - patrz conectivty_test1
            
            max_distance = max(max(ind.stops.distances));
            scale_factor = 5000;
            for i=1:ind.stops.number
                for j=1:ind.stops.number
                    if(ind.shortest_paths(i,j) == Inf)
                        ind.shortest_paths(i,j) = max_distance * scale_factor * ind.stops.number;
                    end
                end
            end
            BUDGET = 1000;
            penalty = 1000000;
            %b=1000000; %TODO: refactor
            ind.total_cost = cost( ind.stops.costs, ind.connections );
            
            o = objective(ind.shortest_paths, ind.stops.wages, 0 );
            
            if(ind.total_cost <= BUDGET )
                ind.objective_value = o;
            else
                ind.objective_value = o + penalty*(ind.total_cost - BUDGET);
            end
        end
    end
    
end

